<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class contact extends Frontend_Controller {
//put your code here
    public function __construct() {
        parent::__construct();
        $view_data = array();
    }
    
    function index(){
        $layout = 'frontend_layout/frontend';
        //
        if(empty($this->cart))$this->load->library('cart');
        $view_data['cart_total'] = $this->cart->total_items();
        $view_data['categories']    = modules::run('ticket/list_ticket_categories');
        $view_data['tags']    = modules::run('ticket/list_ticket_tags');
        
        if(count($_POST)>=4 && isset($_POST['yourname'])){
            //Check validation data
            $this->load->library('form_validation');
            $this->form_validation->set_rules('yourname',__('home_contact_yourname'),'required');
            $this->form_validation->set_rules('yourtitle',__('home_payment_subject'),'required');
            $this->form_validation->set_rules('youremail',__('home_contact_youremail'),'required|valid_email');
            $this->form_validation->set_rules('yourmessage',__('home_contact_yourmessage'),'required');
            if($this->form_validation->run()){
                $this->load->library('email');
                $this->email->clear();
                $this->email->from(EMAIL_CONTACT, $_POST['yourname']);
                $this->email->to($_POST['youremail']);
                $this->email->subject($_POST['yourtitle']);
                $this->email->message($_POST['yourmessage']);
                $this->email->attach($file_path);
                $this->email->send();
                redirect('contact/confirm');
            }
        }
        
        $view_data['main_content'] = $this->load->view('contact',$view_data,true);//modules::run('about_us');
        
        $view_data['title'] = __('home_contact_us');
        $view_data['keywords'] = DEFAULT_KEYWORDS;
        $view_data['description']= DEFAULT_DESCRIPTION;
        $view_data['slideshows_header'] = $this->ticket_model->get_top10ticket_bestseller();//get10TicketBestSeller;
        $this->load->view($layout, $view_data, FALSE);
    }
    
    function confirm(){
        $view_data['confirmed'] = __('contact_confirmed');
        $this->index();        
    }
}
?>
